#include <iostream>
using namespace std;

int tree[10001];
int L,M;
int s,e;
int hasTreeNum = 0;
int main() {
    cin >> L >> M;
    for (int i = 0; i < M; i++)
    {    
        cin >> s >> e;
        for (int j = s; j <= e; j++)
        {
            tree[j] = 1; // 需要移除的树
        }
    }

    if (L < 1 || L > 10000 || M < 1 || M > 100)
    {
        cout << 0;
        return 0;
    }
    
    for (int i = 0; i <= L; i++)
    {
        if (tree[i] == 0)
        {
            hasTreeNum++;
        }
    }
    cout << hasTreeNum;
    
    return 0;
}